package br.com.clinica.supercao.consulta.controller.view;

import java.util.List;

import org.apache.struts2.config.Action;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;

import br.com.clinica.supercao.entity.Animal;
import br.com.clinica.supercao.entity.Consulta;
import br.com.clinica.supercao.entity.Veterinario;
import br.com.clinica.supercao.entity.filter.AnimalSearchFilter;
import br.com.clinica.supercao.entity.filter.ConsultaSearchFilter;
import br.com.clinica.supercao.entity.filter.VeterinarioSearchFilter;
import br.com.clinica.supercao.home.controller.AbstractSuperCaoAction;
import br.com.clinica.supercao.service.AnimalService;
import br.com.clinica.supercao.service.ConsultaService;
import br.com.clinica.supercao.service.VeterinarioService;
import br.com.clinica.supercao.service.impl.AnimalServiceImpl;
import br.com.clinica.supercao.service.impl.ConsultaServiceImpl;
import br.com.clinica.supercao.service.impl.VeterinarioServiceImpl;
import br.com.rpteixeira.exceptions.ServiceExcetion;

@Action(name="Consulta!*",namespace="/model")
@Results({
	@Result(name=ConsultaAction.INIT,value="/jsp/consulta/cadastrarConsulta.jsp"),
	@Result(name=ConsultaAction.INSERT,value="/jsp/consulta/cadastrarConsulta.jsp"),
	@Result(name=ConsultaAction.INSERT_SUCCESS,value="/jsp/homeLogin/homeLogin.jsp")
})
public class ConsultaAction extends AbstractSuperCaoAction<Consulta, ConsultaSearchFilter, ConsultaService> {
	private static final long serialVersionUID = 1L;
	
	private List<Veterinario> veterinarios;
	private List<Animal> animais;
	private Veterinario veterinario;
	private AnimalSearchFilter animal;
	@Override
	protected ConsultaService getEntityService() {
		return new ConsultaServiceImpl();
	}
	public List<Veterinario> getVeterinarios() throws ServiceExcetion {
		if(veterinarios==null){
			veterinarios=getVeterinarioService().findAll();
		}
		return veterinarios;
	}
	
	private VeterinarioService<Veterinario, VeterinarioSearchFilter> getVeterinarioService(){
		return new VeterinarioServiceImpl();
	}

	public List<Animal> getAnimais() throws ServiceExcetion {
		if(animais==null){
			animais=getAnimalService().findAll();
		}
		return animais;
	}

	private AnimalService getAnimalService() {
		return new AnimalServiceImpl();
	}
	public Veterinario getVeterinario() {
		return veterinario;
	}
	public void setVeterinario(Veterinario veterinario) {
		this.veterinario = veterinario;
	}
	public AnimalSearchFilter getAnimal() {
		return animal;
	}
	public void setAnimal(AnimalSearchFilter animal) {
		this.animal = animal;
	}

	
}
